package tcp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class ReceiveByTCP {
    public static void main(String[] args) throws Exception {
        //1.创建ServerSocket对象
        ServerSocket serverSocket=new ServerSocket(12222);
        //2.获取客户端对象
        Socket accept = serverSocket.accept();
        //3.获取输入流
        InputStream inputStream = accept.getInputStream();
        InputStreamReader inputStreamReader=new InputStreamReader(inputStream);
        BufferedReader bufferedReader=new BufferedReader(inputStreamReader);
        int len;
        while ((len=bufferedReader.read())!=-1){
            System.out.print((char) len);
        }
        //4.释放资源
        inputStream.close();
        serverSocket.close();
    }
}
